package com.example.lombok;

import lombok.Cleanup;

import java.io.InputStreamReader;
import java.io.StringBufferInputStream;

/**
 * @author shanchong
 * @date 2019-06-23
 **/
public class CleanupDemo {

    /**
     * @Cleanup：自动管理资源，用在局部变量之前，在当前变量范围内即将执行完毕退出之前会自动清理资源，自动生成try-finally这样的代码来关闭流
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception{
        StringBufferInputStream stringBufferInputStream = new StringBufferInputStream("1111");
        @Cleanup InputStreamReader inputStreamReader = new InputStreamReader(stringBufferInputStream);
        System.out.println(inputStreamReader);
    }

}
